# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>

_gemname=one_gadget
pkgname=${_gemname}
pkgver=1.8.1
pkgrel=2
pkgdesc='The best tool for finding one gadget RCE in libc.so.6'
url='https://github.com/david942j/one_gadget'
arch=('any')
license=('MIT')
depends=('ruby' 'ruby-elftools')
makedepends=('ruby-rake' 'ruby-rdoc' 'ruby-bundler' 'ruby-yard' 'ruby-rspec')
provides=('ruby-one_gadget')
options=('!emptydirs')
source=(${url}/archive/v${pkgver}/${pkgname}-v${pkgver}.tar.gz)
sha512sums=('adfc08ea9079a13327b04fee5c37b1da4ab7b0f99c2012e566096916ca46371dbaf0c618a6be6b7d371a0b6131f010774e3a759092bab54a48702329958cb09e')
b2sums=('f76cda4ac148eb71dca7ac5513818c2d3257c23231b42e6a415921e75a839b4d5145d2f3b9eb7293638de405183fdd9659b7750ff6f3eace6ca4c44c54a775b8')

prepare() {
  cd ${_gemname}-${pkgver}
  sed -r 's|~>|>=|g' -i ${_gemname}.gemspec
  sed -r "s|, '< .*'||g" -i ${_gemname}.gemspec
}

build() {
  cd ${_gemname}-${pkgver}
  gem build ${_gemname}.gemspec
}

package() {
  cd ${_gemname}-${pkgver}
  local _gemdir="$(gem env gemdir)"
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "${pkgdir}${_gemdir}" \
    --bindir "${pkgdir}/usr/bin" \
    ${_gemname}-${pkgver}.gem

  install -Dm 644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"

  cd "${pkgdir}/${_gemdir}"
  rm -rf cache gems/${_gemname}-${pkgver}/{ext,lib/*/*.so,man} \
    extensions/*/*/${_gemname}-${pkgver}/{mkmf.log,gem_make.out}
}

# vim: ts=2 sw=2 et:
